//
//  ChannelNum.m
//  DianNaoWang
//
//  Created by dllo on 15/11/3.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "NormalPageTableViewCell.h"

#import "Header.h"
#import "UIImageView+WebCache.h"
@implementation NormalPageTableViewCell



-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self creatView];
    }
    return self;
}

-(void)creatView
{
    _titleLabel = [[UILabel alloc]init];
    _titleLabel.font = contentTextSize;
    
    _titleLabel.numberOfLines = 0;
    [self.contentView addSubview:_titleLabel];
    
    _dataLabel = [[UILabel alloc]init];
    _dataLabel.font = otherTextSize;
    _dataLabel.textColor = otherTextColor;
    [self.contentView addSubview:_dataLabel];
    
    _label = [[UILabel alloc]init];
    _label.backgroundColor = [UIColor blueColor];
    _label.textColor = [UIColor whiteColor];
    _label.font = otherTextSize;
    _label.layer.cornerRadius = 2;//*****************为啥不好用??????
    _label.clipsToBounds = YES;
    [self.contentView addSubview:_label];
    
    _comment_numLabel = [[UILabel alloc]init];
    _comment_numLabel.font = otherTextSize;
    _comment_numLabel.textColor = otherTextColor;
    [self.contentView addSubview:_comment_numLabel];
    
    _imgsrcView = [[UIImageView alloc]init];
    [self.contentView addSubview:_imgsrcView];
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    _titleLabel.textColor = contenttextColor;
    //标题自适应高度
    _imgsrcView.frame = CGRectMake(10 * FitWidth, 10 * FitHeight, 80 * FitWidth, 70 * FitHeight);
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:contentTextSize, NSFontAttributeName, nil];
    CGRect rect = [_titleLabel.text boundingRectWithSize:CGSizeMake(250 * FitWidth, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    //标签自适应长度
    NSDictionary *dic2 = [NSDictionary dictionaryWithObjectsAndKeys:otherTextSize, NSFontAttributeName, nil];
    CGRect rect2 = [_label.text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, 20 * FitHeight) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic2 context:nil];
    CGRect rect3 = [_comment_numLabel.text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, 20 * FitHeight) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic2 context:nil];
    
    _titleLabel.frame = CGRectMake(_imgsrcView.frame.origin.x + _imgsrcView.frame.size.width + 10 * FitWidth, _imgsrcView.frame.origin.y + 3 * FitWidth, 250 * FitWidth, rect.size.height);
    _dataLabel.frame = CGRectMake(_titleLabel.frame.origin.x, _imgsrcView.frame.origin.y + 50 * FitHeight, 100 * FitWidth, 20 * FitHeight);
    _label.frame = CGRectMake(ScreenWidth - 10 * FitWidth - rect2.size.width, _dataLabel.frame.origin.y + 4 * FitHeight, rect2.size.width, 12 );
    _comment_numLabel.frame = CGRectMake(ScreenWidth - 10 * FitWidth - _label.frame.size.width - rect3.size.width , _dataLabel.frame.origin.y, rect3.size.width, 20 * FitHeight);
}
-(void)setChannelList:(ChannelList *)channelList
{
    if (_channelList != channelList) {
        _channelList = channelList;
    }
    //判断不同type 选择显示不同内容
    if ([channelList.type isEqualToString:@"0"]) {
        _dataLabel.text = [channelList.sdate substringFromIndex:5];
        //判断评论数为0时显示"抢沙发"
        if (channelList.comment_num != 0) {
            NSString *str = [NSString stringWithFormat:@"%ld 评论", channelList.comment_num];
            _comment_numLabel.text = str;
        }else{
            _comment_numLabel.text = @"抢沙发";
        }
        _label.text = channelList.label;
    }else if([channelList.type isEqualToString:@"20"]){
        _dataLabel.text = [channelList.sdate substringFromIndex:5];
        _comment_numLabel.text = channelList.fromplatform;
        _label.text = channelList.label;
    }else if ([channelList.type isEqualToString:@"13"] || [channelList.type isEqualToString:@"18"]){
        _dataLabel.text = [channelList.sdate substringFromIndex:5];
        NSString *str = [NSString stringWithFormat:@"%ld 评论", channelList.comment_num];
        _comment_numLabel.text = str;
        _label.text = @"推荐";
    }else if ([channelList.type isEqualToString:@"19"]){
        _dataLabel.text = [channelList.sdate substringFromIndex:5];
        NSString *str = [NSString stringWithFormat:@"%ld 评论", channelList.comment_num];
        _comment_numLabel.text = str;
        _label.text = @"有奖";
    }
    else{
        _dataLabel.text = nil;
        _comment_numLabel.text = nil;
        _label.text = nil;
    }
    _titleLabel.text = channelList.stitle;
    
    
    //赋值图片:
    [_imgsrcView sd_setImageWithURL:[NSURL URLWithString:channelList.imgsrc] placeholderImage:[UIImage imageNamed:@"123"]];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
